﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Shpm.App.Commons.Utils.CommonSendMessageUtils
 * 类型：       应用共通层
 * 功能说明：   发送消息共通
 * 作者：       zx
 * 创建日期：   2007/12/06
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Input.Bean;
using Shpm.App.Input.Dao;
using System.Collections;
using Shpm.System.Db;

namespace Shpm.App.Commons.Utils
{
    public class CommonSendMessageUtils
    {
        // message info bean
        private MessageBean msgBean = null;

        // to employee id list 
        private string toEmployeeId = string.Empty;
        private string[] toEmployeeIdArray = null;
        private IList toEmployeeIdList = null;

        // Construct
        public CommonSendMessageUtils(MessageBean sendMsgbean,string sendToEmployeeId){
            this.msgBean = sendMsgbean;
            this.toEmployeeId = sendToEmployeeId;
        }

        public CommonSendMessageUtils(MessageBean sendMsgbean, string[] sendToEmployeeIdArray)
        {
            this.msgBean = sendMsgbean;
            this.toEmployeeIdArray = sendToEmployeeIdArray;
        }

        public CommonSendMessageUtils(MessageBean sendMsgbean, ArrayList sentToEmployeeIdList)
        {
            this.msgBean = sendMsgbean;
            this.toEmployeeIdList = sentToEmployeeIdList;
        }

        
        // 检索职员信息 返回职员姓名        
        public int SendMessage()
        {
            try
            {
                string[] employeeIdList = null;
                if (!string.IsNullOrEmpty(this.toEmployeeId))
                {
                    employeeIdList = new string[1];
                    employeeIdList[0] = this.toEmployeeId;
                } else if (this.toEmployeeIdArray != null)
                {
                    employeeIdList = this.toEmployeeIdArray;
                }
                else if (this.toEmployeeIdList != null && this.toEmployeeIdList.Count > 0)
                {
                    employeeIdList = new string[this.toEmployeeIdList.Count];
                    for (Int32 i = 0; i < this.toEmployeeIdList.Count; i++)
                    {
                        employeeIdList[i] = Convert.ToString(this.toEmployeeIdList[i]);
                    }
                }

                MessagesDao dao = new MessagesDao();
                dao.Insert(this.msgBean, employeeIdList, string.Empty);

                return 1;
            }
            catch (Exception e)
            {
                return 0;
            }
        }                
        
    }
}